Skip to content

perf: don't revisit sleeping contacts when bodies wake up or fall asleep - #1078

Open
kylegrahammatzen wants to merge 2 commits into
dimforge:masterfrom
kylegrahammatzen:perf/solver-graph-rebuild-awake-edges
Open

kylegrahammatzen wants to merge 2 commits into
dimforge:masterfrom
kylegrahammatzen:perf/solver-graph-rebuild-awake-edges

Conversation

@kylegrahammatzen

@kylegrahammatzen kylegrahammatzen commented Nov 21, 2026 •

Copy link
Copy Markdown

Every time a body wakes up or falls asleep, Rapier rebuilds its list of contacts for the solver by going through every contact in the world, including all the ones between sleeping bodies that can't change, so waking a single box in a big scene that's mostly at rest takes time in proportion to the whole scene.

Now it only looks at contacts that involve an awake body and gets the same list as before where after a collider is removed or a snapshot is loaded, it still checks everything to be safe.

Waking 1 box among 20,000 asleep Before After
Single-threaded 205 µs 23 µs
Multi-threaded 140–260 µs 26–29 µs

The simulation itself doesn't change, and the existing determinism tests pass with the same hashes.

Waking up or putting to sleep an island made maintain_solver_contact_graph go through every contact pair in the world, sleeping ones included. The rebuild now visits only the pairs whose hint makes them selectable plus the ones the buckets already hold, in increasing order so the graph comes out the same. A new solver_graph_refs_trusted flag falls back to the full walk whenever edges moved without the buckets being fixed up, and debug builds check that no skipped pair still holds a graph position.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant